<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>

<body>

    <template id="sonTemp">
        <div>
            <h3>{{title}}</h3>

            <button @click='changeIt'>点击</button>
        </div>
    </template>
    <!-- 子组件 -->
    <script>
        const son = {
            template: '#sonTemp',
            props: {
                title: String
            },
            created() {
                this.$emit('change-title', { title: '子组件的数据' })
            },
            methods: {
                changeIt() {
                    this.$emit('change-title', { title: '子组件的数据' })
                },
                alertName() {
                    alert('子组件')
                }
            }
        }
    </script>

    <!-- 父组件 -->
    <div id='app'>
        <!-- 属性绑定 -->
        <son ref='son' :title="fatherTitle" @change-title='fatherChange($event)'></son>
        <input type="text" ref='lala'>
        <button @click='getDom'>获取DOM</button>
    </div>
    <script>
        const vm = new Vue({
            el: '#app',
            data: {
                fatherTitle: '父组件传参数'
            },
            components: {
                son
            },
            methods: {
                fatherChange(e) {
                    console.log(e);
                    this.fatherTitle = e.title
                },
                getDom() {
                    this.$refs.son.alertName()
                }
            }
        })
    </script>
</body>

</html>